﻿/**

 @Name：layuiAdmin 用户管理，增删改查
 @Author：马达
 @Site：http://www.sunplus.wang
 @License: 杭州九宸智能科技有限公司
    
 */

layui.define(['table', 'form', 'laydate', 'upload', 'admin'], function (exports) {
    var $ = layui.$
    , admin = layui.admin
    , view = layui.view
    , table = layui.table
    , upload = layui.upload
    , laydate = layui.laydate
    , form = layui.form;

    var varButtonRight = "";
    //文章管理
    table.render({
        elem: '#LAY-app-content-list'
        , toolbar: true  //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
        , defaultToolbar: ['filter']
        , method: "post"
        , url: layui.setter.APIUrl + '/shop/billflowMgr/listPain'
        , headers: { //通过 request 头传递
            Authorization: "bearer " + layui.data('layuiAdmin').access_token
        }
        , parseData: function (res) { //res 即为原始返回的数据 
            varButtonRight = res.Data.ButtonRight;
            return {
                "ResultCode": res.ResultCode, //解析接口状态
                "ResultInfo": res.ResultInfo, //解析提示文本
                "count": res.Data.TotalRecordCount, //解析数据长度
                "Data": res.Data.Items //解析数据列表 
            };
        }
    , cols: [[
      { type: 'checkbox', fixed: 'left', field: 'PID' }, //sort: true  //hide: true //  width:100
		{ field: 'Code', title: '交易单号', minWidth: 140 },
		{ field: 'FlowNumber', title: '商户平台流水号', minWidth: 100 },
		{ field: 'TypeNote', title: '账单类型', width: 120 },
		{
		    field: 'Money', title: '账单金额', width: 100, templet: function (d) {
		        var html = "<span style='color:#FF5722;'>￥</span><span style='color:#FF5722;font-weight:bold;font-size:1em'>" + d.Money + "</span>";
		        return html;
		    }
		},
		{ field: 'Mode', title: '支付方式', width: 100 },
		{
		    field: 'UserName', title: '用户', minWidth: 180, templet: function (d) {
		        var html = d.MemberCode + " &nbsp;<span>" + d.UserName + "</span>";
		        return html;
		    }
		},
		//{ field: 'Type', title: '账单类型 账单类型[0.订单支付|1.订单退款|2.其他]'},                                         
		//{ field: 'Account', title: '支付平台账号'},                            
		{
		    field: 'State', title: '账单状态', width: 100, templet: function (d) {
		        var html = "";
		        if (d.State == 0) {
		            html = "<span style='color:#FF5722;font-weight:bold'>未完成</span>";
		        } else if (d.State == 1) {
		            html = "<span style='color:#5FB878;font-weight:bold'>已完成</span>";
		        } else if (d.State == 2) {
		            html = "<span style='color:#c2c2c2;font-weight:bold'>取消</span>";
		        } else {
		            html = "<span style='color:#2F4056;font-weight:bold'>交易失败</span>";
		        }
		        return html;
		    }
		},
		//{ field: 'Other1', title: '商户号'}, 
		{ field: 'StoreName', title: '店铺' },
		{ field: 'CreateTime', title: '创建时间', templet: '<div>{{ Format(d.CreateTime,"yyyy-MM-dd hh:mm:ss") }}</div>' },
		{ field: 'SuccessTime', title: '交易成功时间' ,templet: '<div>{{ Format(d.SuccessTime,"yyyy-MM-dd hh:mm:ss") }}</div>' },                         
      {
          title: '操作', width: 90, fixed: 'right', align: 'center', templet: function (d) {
              var strRtn = "";
              if (varButtonRight.indexOf('view') >= 0) {
                  strRtn += "<a class=\"layui-btn layui-btn-primary layui-btn-xs\" lay-event=\"view\">查看</a> ";
              }
              //if (varButtonRight.indexOf('edit') >= 0) {
              //    strRtn += "<a class=\"layui-btn layui-btn-normal layui-btn-xs\" lay-event=\"edit\">编辑</a> ";
              //}
              //if (varButtonRight.indexOf('del') >= 0) {
              //    strRtn += "<a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"del\">删除</a> ";
              //}
              return strRtn;
          }
      } 
    ]]
    , page: true
    , limit: 10
    , limits: [10, 15, 20, 25, 30]
    , text: {
        none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增 text: '对不起，加载出现异常！'
    }
    });

    //监听工具条
    table.on('tool(LAY-app-content-list)', function (obj) {
        //debugger;
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('确定删除吗？', function (index) {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/billflowMgr/BatchDelete' //实际使用请改成服务端真实接口
                  , data: { "ids": data.PID }
                  , type: "post"
                    //, success: function (res) {
                    //}
                  , done: function (res) {
                      layer.close(index); //执行关闭 
                      table.reload('LAY-app-content-list');
                      layer.msg('删除成功');
                  }
                });
            });
        }
        else if (obj.event === 'edit') {
            //location.hash = '/shop/shop_billflow/addChild/id=' + data.PID;
            admin.popup({
                title: '编辑信息'
                , area: ['850px', '650px']
              , id: 'LAY-popup-content-edit'
              , success: function (layero, index) {
                  view(this.id).render('/shop/shop_billflow/add', data).done(function () {
                      form.render(null, 'layuiadmin-app-form-list');

                      //监听提交
                      form.on('submit(layuiadmin-app-form-submit)', function (data) {
                          var field = data.field; //获取提交的字段 
                          //提交 Ajax 成功后，关闭当前弹层并重载表格 
                          admin.req({
                              url: layui.setter.APIUrl + '/shop/billflowMgr/update' //实际使用请改成服务端真实接口
                          , data: field
                          , type: "post"
                          , done: function (res) {
                              layui.table.reload('LAY-app-content-list'); //重载表格
                              layer.close(index); //执行关闭
                              layer.msg('修改成功');
                          }
                          });
                      });
                  });
              }
            });
        }
        else if (obj.event === 'view') {
            admin.popup({
                title: '查看信息'
               , area: ['58%', '80%']
             , id: 'LAY-popup-content-view'
             , success: function (layero, index) {
                 view(this.id).render('/shop/shop_billflow/view', data).done(function () {
                     form.render(null, 'layuiadmin-app-form-list');
                     //监听提交
                     form.on('submit(layuiadmin-app-form-submit)', function (data) {
                         layer.close(index); //执行关闭
                     });
                 });
             }
            });
        }
    });

    exports('shop_billflow', {})

});
